package net.actions.site;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.base.BaseAction;
import net.base.BaseDao;

import org.apache.log4j.Logger;

public class SiteItemAction extends BaseAction{
	private BaseDao dao = null;

    public BaseDao getDao() {
        return dao;
    }

    public void setDao(BaseDao dao) {
        this.dao = dao;
    }

    private Logger log = Logger.getLogger(this.getClass());
    /**
     * 取新闻栏目树
     * @return
     */
    public String getSiteItemTree(){
    	try{
    		StringBuffer rtn = new StringBuffer();
    		rtn.append("[");
    		List list = dao.getList("site.site_item.getSITE_ITEM", null);
    		for(Iterator it=list.iterator();it.hasNext();){
    			Map map = (Map)it.next();
    			rtn.append("{id:" +map.get("ID") + ",pId:" + map.get("PID")+",name:\""+ map.get("NAME") +"\"},");
    		}
    		if(rtn.length()>1)
    			rtn = new StringBuffer(rtn.substring(0,rtn.length()-1));
    		rtn.append("]");
    		this.msg = rtn.toString();
    	}catch(Exception e){
    		e.printStackTrace();
            log.error(e.toString());
            this.code = -1;
            this.msg = "查询失败！\n" + e.toString();
            this.expMsg = getExceptionMessage(e);
    	}
    	return getResult();
    }
}
